# Author   : zhen.fang
# Time     : 2020/10/17 23:45
# Email    : fangeddie@163.com
from django.contrib.auth import forms as auth_forms
from django import forms
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _


class RegisterForm(auth_forms.UserCreationForm):
    """
    UserCreationForm 没有去获取 email
    """
    email = forms.EmailField(min_length=7, label="邮箱", required=False, error_messages={"min_length": "邮箱太短了"})


class ActiveAuthenticationForm(auth_forms.AuthenticationForm):
    pass


class PasswordChangeForm(auth_forms.PasswordChangeForm):
    pass


class PasswordResetForm(auth_forms.PasswordResetForm):
    # 实现"邮箱未注册"的提示
    def clean_email(self):
        email = self.cleaned_data.get("email", "")
        if not User.objects.filter(email=email):
            raise forms.ValidationError("邮箱未注册")
        return email

class SetPasswordForm(auth_forms.PasswordResetForm):
    pass